package leetcode;

import java.util.*;
import java.util.stream.Collectors;

public class Lc3043 {



    public int longestCommonPrefix(int[] arr1, int[] arr2) {
        HashSet<Integer> set = new HashSet<>();
        for (int i = 0; i < arr1.length; i++) {
            int x = arr1[i];
            while (x != 0) {
                set.add(x);
                x /= 10;
            }
        }

        int maxLong = 0;
        for (int i = 0; i < arr2.length; i++) {
            int x = arr2[i];
            while (x != 0) {
                if (set.contains(x)) {
                    maxLong = Math.max(maxLong, x);
                }
                x /= 10;
            }
        }
        return maxLong == 0 ? 0 : String.valueOf(maxLong).length();
    }




    public static void main(String[] args) {
        Lc3043 lc3043 = new Lc3043();
        int[] a1 ={123};
        int[] a2 = {124};
//        int[] a1 = {474,2907,2219,1527,1993,1847,4205,2666,3835,583,1336,1338,2432,2406,710,3927,4138,3492,2823,2857,3051,81,4356,1752,2565,1593,247,3067,4039,309,4400,2058,3671,2989,4111,4301,862,2845,1369,1208,4940,1780,2152,419,133,835,4841,773,3148,1301};
//        int[] a2 = {2918,3956,2242,2824,1235,562,1844,4315,1477,4471,2893,933,4957,649,3534,2169,4716,1534,497,4744,464,3,2608,549,66,2169,4183,1900,2962,1985,3895,2431,3694,985,2901,4929,3851,3551,3485,4701,3922,4849,659,3387,1428,1101,4264,2518,3982,2826};
        System.out.println(lc3043.longestCommonPrefix(a1, a2));

    }


}
